package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("与数据库连接成功！");
        Statement stat = conn.createStatement();
        String sql = "INSERT INTO userinfo(username,password,nickname,age)\n" +
                "VALUES ('张三','password','三娃',13),\n" +
                "       ('李四','password','四娃',14),\n" +
                "        ('王五','password','小黑',15)";
        int num = stat.executeUpdate(sql);
        System.out.println(num > 0 ? "添加成功" : "添加失败");

        conn.close();

    }
}
